﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ORolePowerList.aspx.cs" Inherits="IHISCETeim.Web.MachineSys.SysBasic.ORolePowerList" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>角色权限</title>
    <style>
        ul.powers {
            margin: 0;
            padding: 0;
        }

            ul.powers li {
                margin: 5px 15px 5px 0;
                display: inline-block;
                min-width: 150px;
            }

                ul.powers li input {
                    vertical-align: middle;
                }

                ul.powers li label {
                    margin-left: 5px;
                }

        /* 自动换行，放置权限列表过长 */
        .x-grid-row .x-grid-cell-inner {
            white-space: normal;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
        <f:PageManager ID="PageManager1" AutoSizePanelID="RegionPanel1" runat="server"></f:PageManager>
        <f:RegionPanel ID="RegionPanel1" ShowBorder="false" runat="server">
            <Regions>
                <f:Region ID="Region1" ShowBorder="false" ShowHeader="false" Width="250px" Position="Left" Layout="Fit" BodyPadding="5px" runat="server">
                    <Items>
                        <f:Grid ID="Grid1" Width="400px" runat="server" AutoScroll="true" ShowBorder="true" ShowHeader="false" EnableCheckBoxSelect="false" DataKeyNames="RoleId" AllowPaging="false" OnRowClick="Grid1_RowClick" EnableRowClickEvent="false" AllowCellEditing="true" ClicksToEdit="1" OnRowCommand="Grid1_RowCommand" OnPreDataBound="Grid1_PreDataBound">
                            <Toolbars>
                                <f:Toolbar ID="Toolbar2" runat="server">
                                    <Items>
                                        <f:Button ID="btnAddRole" EnablePostBack="false" Icon="Add" runat="server" Text="添加角色"></f:Button> 
                                         <f:Button ID="btnSave" runat="server" Text="保存" OnClick="btnSave_Click" ></f:Button>                                      
                                    </Items>
                                </f:Toolbar>
                            </Toolbars>
                            <Columns>
                                <f:RowNumberField></f:RowNumberField>                                
                                <f:RenderField  ColumnID="RoleName" DataField="RoleName" FieldType="String" HeaderText="角色名称" ExpandUnusedSpace="true" >
                                    <Editor>
                                        <f:TextBox ID="tbxRoleName" Required="true" runat="server"></f:TextBox>
                                    </Editor>
                                </f:RenderField>  
                                <f:LinkButtonField CommandName="ViewSub" HeaderText="显示权限" TextAlign="Center" Width="60px" Icon="ApplicationGo" />
                                <f:LinkButtonField ColumnID="Delete" HeaderText="删除" Width="40px" TextAlign="Center" EnablePostBack="false" Icon="Delete" />
                            </Columns>
                        </f:Grid>
                    </Items>
                </f:Region>
                <f:Region ID="Region2" ShowBorder="false" ShowHeader="false" Position="Center" Layout="Fit" BodyPadding="5px 5px 5px 0" runat="server">
                    <Items>
                        <f:Grid ID="Grid2" runat="server" ShowBorder="true" ShowHeader="false" EnableColumnLines="true" EnableMultiSelect="false" EnableCheckBoxSelect="false" DataKeyNames="MenuId,MenuName" OnRowDataBound="Grid2_RowDataBound" >
                            <Toolbars>
                                <f:Toolbar ID="Toolbar1" runat="server">
                                    <Items>
                                        <f:Button ID="btnSelectAll" EnablePostBack="false" runat="server" Text="全选">
                                        </f:Button>
                                        <f:Button ID="btnUnSelectAll" EnablePostBack="false" runat="server" Text="反选">
                                        </f:Button>
                                        <f:ToolbarSeparator ID="ToolbarSeparator1" runat="server">
                                        </f:ToolbarSeparator>
                                        <f:Button ID="btnGroupUpdate" Icon="GroupEdit" runat="server" Text="更新当前角色的权限" OnClick="btnGroupUpdate_Click">
                                        </f:Button>
                                    </Items>
                                </f:Toolbar>
                            </Toolbars>
                            <Columns>
                                <f:RowNumberField Width="40px" TextAlign="Center"></f:RowNumberField>  
                                <f:TemplateField HeaderText="所属系统"  Width="90px">
                                    <ItemTemplate>
                                        <%# Convert.ToBoolean(Eval("IsAgent"))?"经销商平台":"信息平台" %>
                                    </ItemTemplate>
                                </f:TemplateField>                             
                                <f:TemplateField HeaderText="上级菜单"  Width="150px">
                                    <ItemTemplate>
                                        <asp:Label runat="server" ID="lbParMenuName" Text=""></asp:Label>
                                    </ItemTemplate>
                                </f:TemplateField>
                                <f:BoundField DataField="MenuName" SortField="MenuName" HeaderText="菜单名称" Width="150px"></f:BoundField>
                                <f:TemplateField ExpandUnusedSpace="true" HeaderText="权限列表">
                                    <ItemTemplate>
                                        <asp:CheckBoxList ID="ddlPowers" CssClass="powers" RepeatLayout="UnorderedList" RepeatDirection="Vertical" runat="server">
                                        </asp:CheckBoxList>
                                    </ItemTemplate>
                                </f:TemplateField>
                            </Columns>
                        </f:Grid>
                    </Items>
                </f:Region>
            </Regions>
        </f:RegionPanel>
        <f:Menu ID="Menu2" runat="server">
            <f:MenuButton ID="menuSelectRows" EnablePostBack="false" runat="server" Text="全选行">
            </f:MenuButton>
            <f:MenuButton ID="menuUnselectRows" EnablePostBack="false" runat="server" Text="取消行">
            </f:MenuButton>
        </f:Menu>
    </form>
    <script src="../../AgentSys/res/js/jquery-1.10.2.min.js"></script>
    <script>
        var grid2ID = '<%= Grid2.ClientID %>';
        var btnSelectAll = '<%= btnSelectAll.ClientID %>';
        var btnUnSelectAll = '<%= btnUnSelectAll.ClientID %>';

        var menuID = '<%= Menu2.ClientID %>';
        var menuSelectRows = '<%= menuSelectRows.ClientID %>';
        var menuUnselectRows = '<%= menuUnselectRows.ClientID %>';


        F.ready(function () {
            var grid = F(grid2ID), gridEl = $(grid.el.dom);
            var checkboxSelector = '.powers input[type=checkbox]',
                selectedRowSelector = '.x-grid-row-selected',
                selectedRowCheckboxSelector = selectedRowSelector + ' ' + checkboxSelector;


            F(grid2ID).on('beforeitemcontextmenu', function (view, record, item, index, event) {
                F(menuID).showAt(event.getXY());
                event.stopEvent();
            });


            function selectCheckbox(checked) {
                var selectedRows = gridEl.find(selectedRowSelector);
                if (selectedRows.length) {
                    gridEl.find(selectedRowCheckboxSelector).prop('checked', checked);
                } else {
                    gridEl.find(checkboxSelector).prop('checked', checked);
                }
            }

            F(menuSelectRows).on('click', function () {
                selectCheckbox(true);
            });

            F(menuUnselectRows).on('click', function () {
                selectCheckbox(false);
            });


            F(btnSelectAll).on('click', function () {
                selectCheckbox(true);
            });
            F(btnUnSelectAll).on('click', function () {
                selectCheckbox(false);
            });

        });
        
    </script>
</body>
</html>
